from typing import List

class Solution:
    def findRightInterval(self, intervals: List[List[int]]) -> List[int]:
        ans = [-1] * len(intervals)
        sortIntervals = sorted([(item[0], item[1], idx) for idx, item in enumerate(intervals)])
        for i in range(len(sortIntervals)):
            item = sortIntervals[i]
            left, right, target = i, len(sortIntervals) - 1, -1
            while left <= right:
                mid = (left + right) // 2
                if sortIntervals[mid][0] >= item[1]:
                    target = sortIntervals[mid][2]
                    right = mid - 1
                else:
                    left = mid + 1
            ans[item[2]] = target
        return ans